home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / demo3.zoo / demo / misc / grav.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-24  |  2.4 KB  |  99 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: grav.c,v 4.3 88/06/30 11:41:44 sau Exp $
  9.     $Source: /tmp/mgrsrc/demo/misc/RCS/grav.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /tmp/mgrsrc/demo/misc/RCS/grav.c,v $$Revision: 4.3 $";
  12.  
  13. #include <sys/time.h>
  14. #include <stdio.h>
  15. #include "term.h"
  16. #include "restart.h"
  17.  
  18. #define MAXX    999
  19. #define MAXY    999
  20. #define MAXV    60
  21. #define MINV    20
  22. #define LCT    10
  23. #define SLOW    60000        /* usec to sleep between lines */
  24. #define ACC     2
  25. #define fsleep(x) \
  26.    { \
  27.    struct timeval time; \
  28.    time.tv_sec = 0; \
  29.    time.tv_usec = x; \
  30.    select(0,0,0,0,&time); \
  31.    }
  32. #define abs(x)    ((x) < 0 ? -(x) : (x))
  33.  
  34. int vx, vy; /* x and y velocities */
  35. int x, y, x1, y1;
  36. int rad, hsize, vsize;
  37. int lcolor,bcolor;
  38. long random();
  39.  
  40. main(argc,argv)
  41. char **argv;
  42. {
  43.     char *getenv();
  44.         register int s = 0;
  45.     int sleep = 0;
  46.  
  47.     ckmgrterm( *argv );
  48.  
  49.     if (argc>1 && strcmp(argv[1],"-s")==0)
  50.         sleep++;
  51.  
  52.     m_setup(0);
  53.     m_push(P_EVENT|P_FLAGS);
  54.         Restart();
  55.     get_size(&x, &y, &hsize, &vsize);
  56.     rad = (vsize+hsize)>>6;/* size is the avg. of dims. / 32 */
  57.  
  58.     vx = 5; /* constant horizontal velocity */
  59.     vy = 0;  /* initial vertical velocity of zero */
  60.     x = rad + 1;
  61.     y = rad + 1;
  62.     m_setevent(UNCOVERED,_quit);
  63.     
  64.     bcolor = random()%24;
  65.     m_bcolor(bcolor);
  66.     while((lcolor = random()%24) == bcolor);
  67.     m_linecolor(B_SRC,lcolor);
  68.     m_fcolor(lcolor);
  69.     m_clear();
  70.     m_circle(x,y,rad);
  71.     for(;;)
  72.     {
  73.         x1 = x +vx; /* add velocity to x */
  74.         if (x1 > MAXX-rad || x1 < rad) {
  75.         /* fix coords if over border */
  76.             vx *= -1;
  77.             x1 += vx;
  78.         }
  79.         vy += ACC; /* accelerate vertical velocity */
  80.         y1 = y + vy; /* add velocity to y */
  81.         if (y1 > MAXY-rad || y1 < rad) {
  82.                     m_circle(x1,MAXY-rad,rad);
  83.             vy = -vy * 95 /100;
  84.                         if (abs(vy) < ACC) {
  85.                            fsleep(900000);
  86.                            m_sendme(_quit);
  87.                            }
  88.             y1 += vy;
  89.         }
  90.         m_circle(x1,y1,rad); /* draw new position */
  91.         x = x1; /* reset x and y */
  92.         y = y1;
  93.         m_flush();
  94.         if (sleep)
  95.            fsleep(90000);
  96.     }
  97. }
  98.  
  99.